﻿using System;
using System.Reflection;
using AllInOnePluginBL.Helpers;
using NLog;

namespace AllInOnePluginBL.SiteScrappers
{
    /// <summary>
    /// Summary description for BaseSiteScrapper
    /// </summary>
    public abstract class BaseSiteScrapper : ISiteScapper
    {
        #region Protected Members
        protected readonly Logger _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.Name);
        protected readonly PluginDBHandler _pluginDBHandler = PluginDBHandler.Instance; 
        #endregion

        #region Publilc Properties
        public string Name { get; protected set; }

        public JobType JobType { get; set; }

        public long JobID { get; set; } 
        #endregion

        #region Ctor
        protected BaseSiteScrapper(string name)
        {
            if (string.IsNullOrEmpty(name)) throw new Exception("Name cant be empty");

            this.Name = name;
            this.JobType = JobType.SiteScrapper;

            var job = _pluginDBHandler.GetJob(this.Name) ??
                          _pluginDBHandler.CreateJob(this.Name, this.JobType.ToString());

            this.JobID = job.JobID;
        } 
        #endregion

        #region Virtual Methods
        public virtual void Execute(int pagesToScan)
        {
            throw new System.NotImplementedException();
        } 
        #endregion
    }
}